/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cs425proj.model;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.*;


/**
 *
 * @author prateekpatil
 */
public class movieDetail {
    
    private int movieid;
    private String moviename ;
    private String desc ;
    private String type ;
    private int rating;
    private int  duration ;
    
    
    //Get details on movie id
    public void setMovieDetail(int id)
    {
        ResultSet rs;
        try{
        connectDB obj = new connectDB();
        
        Statement stm;
        stm =  obj.startConnection().createStatement();
        //Querries
        rs = stm.executeQuery("select * from movie where movie_id="+id);
        while(rs.next()){
                this.setMovieid(rs.getInt(1));
                this.setMoviename(rs.getString(2));
                this.setType(rs.getString(3));
                this.setDesc(rs.getString(4));
                this.setRating (rs.getInt(5));
                this.setDuration(rs.getInt(6));
        }
             
        
        obj.closeConnection();
        }catch(SQLException e){e.printStackTrace();}
              
    
    }
    
    
    //Get details on movie name 
     public void setMovieDetail(String movieName)
    {
        ResultSet rs;
        try{
        connectDB obj = new connectDB();
        
        Statement stm;
        stm =  obj.startConnection().createStatement();
        //Querries
        rs = stm.executeQuery("select * from movie where name ='"+movieName+"'");
        while(rs.next()){
                this.setMovieid(rs.getInt(1));
                this.setMoviename(rs.getString(2));
                this.setType(rs.getString(3));
                this.setDesc(rs.getString(4));
                this.setRating (rs.getInt(5));
                this.setDuration(rs.getInt(6));
        }
        
        obj.closeConnection();
        }catch(SQLException e){e.printStackTrace();}
              
    
    }
     
     public ArrayList<String> getMoviesInCity(String city)
     {
        ArrayList<String> movieList = new ArrayList<String>();
        ResultSet rs;
        try{
        connectDB obj = new connectDB();
        Statement stm;
        stm =  obj.startConnection().createStatement();
        String qry="select name from movie where movie_id in(select distinct(movie_id) from schedule where screen_id in (select screen_id from screen where theater_id in(select theater_id from theater where city='"+city+"' ) ))";
        rs = stm.executeQuery(qry);
        while(rs.next()){
                movieList.add(rs.getString(1));
        }
             
        
        obj.closeConnection();
        }catch(SQLException e){e.printStackTrace();}
        
        return movieList;
     }
     
      public ArrayList<String> getMoviesList()
     {
        ArrayList<String> movieList = new ArrayList<String>();
        ResultSet rs;
        try{
        connectDB obj = new connectDB();
        Statement stm;
        stm =  obj.startConnection().createStatement();
        String qry="select * from movie ";
        rs = stm.executeQuery(qry);
        while(rs.next()){
                movieList.add(rs.getInt(1)+" "+rs.getString(2) );
        }
             
        
        obj.closeConnection();
        }catch(SQLException e){e.printStackTrace();}
        
        return movieList;
     }
    
    public String getDesc() {
        return desc;
    }

    public void setDesc(String desc) {
        this.desc = desc;
    }

    public int getDuration() {
        return duration;
    }

    public void setDuration(int duration) {
        this.duration = duration;
    }

    public String getMoviename() {
        return moviename;
    }

    public int getMovieid() {
        return movieid;
    }

    public int getRating() {
        return rating;
    }

    public String getType() {
        return type;
    }

    public void setMovieid(int movieid) {
        this.movieid = movieid;
    }

    public void setMoviename(String moviename) {
        this.moviename = moviename;
    }

    public void setRating(int rating) {
        this.rating = rating;
    }

    public void setType(String type) {
        this.type = type;
    }

   
    
    
    
    
}
